package com.ruoyi.record.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.firefighter.domain.FirefighterInfo;
import com.ruoyi.firefighter.service.IFirefighterInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.record.mapper.FirefighterRecordMapper;
import com.ruoyi.record.domain.FirefighterRecord;
import com.ruoyi.record.service.IFirefighterRecordService;

/**
 * 个人履历Service业务层处理
 *
 * @author ruoyi
 * @date 2024-10-11
 */
@Service
public class FirefighterRecordServiceImpl implements IFirefighterRecordService
{
    @Autowired
    private FirefighterRecordMapper firefighterRecordMapper;
    @Autowired
    private IFirefighterInfoService iFirefighterInfoService;
    /**
     * 查询个人履历
     *
     * @param id 个人履历主键
     * @return 个人履历
     */
    @Override
    public FirefighterRecord selectFirefighterRecordById(Long id)
    {
        return firefighterRecordMapper.selectFirefighterRecordById(id);
    }

    /**
     * 查询个人履历列表
     *
     * @param firefighterRecord 个人履历
     * @return 个人履历
     */
    @Override
    public List<FirefighterRecord> selectFirefighterRecordList(FirefighterRecord firefighterRecord)
    {
        return firefighterRecordMapper.selectFirefighterRecordList(firefighterRecord);
    }

    /**
     * 新增个人履历
     *
     * @param firefighterRecord 个人履历
     * @return 结果
     */
    @Override
    public int insertFirefighterRecord(FirefighterRecord firefighterRecord)
    {
        FirefighterInfo firefighterInfo1 = new FirefighterInfo();
        firefighterInfo1.setIdCardNumber(firefighterRecord.getFirefighterIdCard());
        FirefighterInfo firefighterInfo= iFirefighterInfoService.selectFirefighterInfoBySfz(firefighterInfo1);
        if (firefighterInfo==null){
            return 0;
        }
        firefighterRecord.setFirefighterId(firefighterInfo.getUserId());
        firefighterRecord.setCreateTime(DateUtils.getNowDate());
        return firefighterRecordMapper.insertFirefighterRecord(firefighterRecord);
    }

    /**
     * 修改个人履历
     *
     * @param firefighterRecord 个人履历
     * @return 结果
     */
    @Override
    public int updateFirefighterRecord(FirefighterRecord firefighterRecord)
    {
        firefighterRecord.setUpdateTime(DateUtils.getNowDate());
        return firefighterRecordMapper.updateFirefighterRecord(firefighterRecord);
    }

    /**
     * 批量删除个人履历
     *
     * @param ids 需要删除的个人履历主键
     * @return 结果
     */
    @Override
    public int deleteFirefighterRecordByIds(Long[] ids)
    {
        return firefighterRecordMapper.deleteFirefighterRecordByIds(ids);
    }

    /**
     * 删除个人履历信息
     *
     * @param id 个人履历主键
     * @return 结果
     */
    @Override
    public int deleteFirefighterRecordById(Long id)
    {
        return firefighterRecordMapper.deleteFirefighterRecordById(id);
    }

    @Override
    public void deleteFirefighterRecordById1(Long userId) {
         firefighterRecordMapper.deleteFirefighterRecordByUserid(userId);
    }
}
